
<?php get_main_menu("admin")?>
   <br/>
   <div style="width:90%; margin-left:auto; margin-right:auto;">
    <div class="form_title">

            <?php echo $_REQUEST["action"];?> Material Service Cost <?php echo $row_get_branch_by_id['name']?>
    </div>
    <div class="box"> 
<?php
$colname_material_service_cost_by_id = "-1";
if (isset($_GET['id'])) {
  $colname_material_service_cost_by_id = $_GET['id'];
}
mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_material_service_cost_by_id = sprintf("SELECT * FROM material_service_cost WHERE id = %s", GetSQLValueString($colname_material_service_cost_by_id, "int"));
$material_service_cost_by_id = mysql_query($query_material_service_cost_by_id, $drycleaners_conn) or die(mysql_error());
$row_material_service_cost_by_id = mysql_fetch_assoc($material_service_cost_by_id);
$totalRows_material_service_cost_by_id = mysql_num_rows($material_service_cost_by_id);

mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_service = "SELECT * FROM service";
$service = mysql_query($query_service, $drycleaners_conn) or die(mysql_error());
$row_service = mysql_fetch_assoc($service);
$totalRows_service = mysql_num_rows($service);


mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_item = "SELECT * FROM item";
$item = mysql_query($query_item, $drycleaners_conn) or die(mysql_error());
$row_item = mysql_fetch_assoc($item);
$totalRows_item = mysql_num_rows($item);

mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_period = "SELECT * FROM period";
$period = mysql_query($query_period, $drycleaners_conn) or die(mysql_error());
$row_period = mysql_fetch_assoc($period);
$totalRows_period = mysql_num_rows($period);

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "material_service_cost_form")  && isset($_REQUEST["save"])) {
  $insertSQL = sprintf("INSERT INTO `material_service_cost` (period_id, material_id,item_id,service_id, price,express_extra_price,  created_by, 	created_date, record_status)
   VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['period_id'], "int"),
					   GetSQLValueString($_POST['material_id'], "int"),
					   GetSQLValueString($_POST['item_id'], "int"),
					   GetSQLValueString($_POST['service_id'], "int"),
					   GetSQLValueString($_POST['price'], "int"),
					   GetSQLValueString($_POST['express_extra_price'], "int"),
                       GetSQLValueString($loggedin_id, "int"),
                       GetSQLValueString(date("y-m-d"), "date"),
                       GetSQLValueString($_POST['record_status'], "text"));

  mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
  $Result1 = mysql_query($insertSQL, $drycleaners_conn) or die(mysql_error());
  
  if(mysql_affected_rows($drycleaners_conn)){
	  redirect_drycleaners("material_service_cost_view&material_id=".$_POST['material_id']."","2");
	  }
}
?>

<?php
 if(isset($_REQUEST["update"])){
			if(isset($_REQUEST["id"])){
			mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
			$query_update_user="update material_service_cost set period_id='".$_REQUEST['period_id']."',service_id='".$_REQUEST['service_id']."', item_id='".$_REQUEST['item_id']."',price='".$_REQUEST['price']."',express_extra_price='".$_REQUEST['express_extra_price']."' WHERE material_service_cost.id='".$_REQUEST["id"]."'";
			$results_user=mysql_query($query_update_user,$drycleaners_conn) or die(mysql_error());
				redirect_drycleaners("material_service_cost_view&material_id".$_POST['material_id']."","2");
			}
 			}
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="Role" id="material_service_cost_form">
  <table align="left">
    <tr valign="baseline">
     <td nowrap="nowrap" align="left">Period</td>
     <td><select name="period_id">
        <?php
do {  
?>
        <option value="<?php echo $row_period['id']?>"<?php if (!(strcmp($row_period['id'], $row_user_by_id['period_id']))) {echo "selected=\"selected\"";} ?>><?php echo date("d-M",strtotime($row_period['open_date']))." -- ".date("d-M",strtotime($row_period['close_date']))." ".$row_period['year']?></option>
        <?php
} while ($row_period = mysql_fetch_assoc($period));
  $rows = mysql_num_rows($period);
  if($rows > 0) {
      mysql_data_seek($period, 0);
	  $row_period = mysql_fetch_assoc($period);
  }
?>
      </select></td>
 </tr>
 <tr valign="baseline">
  <td nowrap="nowrap" align="left">Service</td>
          <td><select name="service_id">
        <?php
do {  
?>
        <option value="<?php echo $row_service['id']?>"<?php if (!(strcmp($row_service['id'], $row_user_by_id['service_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_service['name']?></option>
        <?php
} while ($row_service = mysql_fetch_assoc($service));
  $rows = mysql_num_rows($service);
  if($rows > 0) {
      mysql_data_seek($service, 0);
	  $row_service = mysql_fetch_assoc($service);
  }
?>
      </select></td>
    </tr>
      <td nowrap="nowrap" align="left">Item</td>
          <td><select name="item_id">
        <?php
do {  
?>
        <option value="<?php echo $row_item['id']?>"<?php if (!(strcmp($row_item['id'], $row_user_by_id['item_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_item['name']?></option>
        <?php
} while ($row_item = mysql_fetch_assoc($item));
  $rows = mysql_num_rows($item);
  if($rows > 0) {
      mysql_data_seek($item, 0);
	  $row_item = mysql_fetch_assoc($item);
  }
?>
      </select></td>
    </tr>
         <tr valign="baseline">
      <td nowrap="nowrap" align="left">Price</td>
      <td><input type="text" name="price" value="<?php echo $row_material_service_cost_by_id['price']; ?>" size="32" /></td>
    </tr>
   <tr valign="baseline">
      <td nowrap="nowrap" align="left">Express Extra Price</td>
      <td><input type="text" name="express_extra_price" value="<?php echo $row_material_service_cost_by_id['express_extra_price']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="left">&nbsp;</td>
      <td> <?php if(isset($_REQUEST['material_service_cost_edit'])){	
		echo"<input name='update' type='submit' value='UPDATE' id='submit'/>";
		echo"<input type='hidden' name='MM_update' value='material_service_cost_form' />";
		echo"&nbsp;&nbsp;<a href='.?material_service_cost_view&material_id".$_REQUEST['material_id']."'><input name='add' type='button' value='Cancel' id='submit'/></a>";
		
		}
		else{
			echo"<input name='save' type='submit' value='SAVE' id='submit'/>";
			echo"<input type='hidden' name='MM_insert' value='material_service_cost_form' />";	
			echo"&nbsp;&nbsp;<a href='.?material_service_cost_view&material_id=".$_REQUEST['material_id']."'><input name='add' type='button' value='Cancel' id='submit'/></a>";
			}
		?></td>
    </tr>
  </table>
  <input type="hidden" name="record_status" value="active" />
  <input type="hidden" name="id" value="<?php echo $row_material_service_cost_by_id['id']; ?>" />
  <input type="hidden" name="material_id" value="<?php echo $_REQUEST['material_id']; ?>" />
  <input type="hidden" name="MM_insert" value="material_service_cost_form" />
</form><?php
mysql_free_result($material_service_cost_by_id);

mysql_free_result($service);

mysql_free_result($period);
?>
</div>